class Solution {
public:
    double myPow(double x, int n) {
        if (n >= 0)
        {
            return pow(x, n);
        }
        else
        {
            double tmp = pow(x, -(long long)n);
            return 1 / tmp;
        }
    }

    double pow(double x, long long n)
    {
        if (n == 0)
            return 1;

        double tmp = myPow(x, n / 2);

        return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;
    }
};